package com.itheima.controller;

import com.github.pagehelper.PageHelper;
import com.itheima.domain.Dept;
import com.itheima.service.DeptServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class DeptController {
          DeptServiceImpl  deptServiceImpl = new DeptServiceImpl();

    /*
     * 查询*/
    @Test
    public void selectAllDept(){
        List<Dept> lists = deptServiceImpl.selectAllDept();
        for (Dept list:lists) {
            System.out.println(list);
        }
    }
    /*查询单个
     * */
    @Test
    public void selectByDept(){
        Dept dept = deptServiceImpl.selectByDept(10);
        System.out.println(dept);
    }


    /*
     *添加
     * */
    @Test
    public void insertDept(){
        Dept dept = new Dept(60,"department","shanghai");
        int ins = deptServiceImpl.insertDept(dept);
        if(ins>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
    }
    /*
     * 删除
     * */
    @Test
    public void deleteDept(){
        int delete = deptServiceImpl.deleteDept(50);
        if(delete>=0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }
    /*
     *更新
     * */
    @Test
    public void updateDept(){
        Dept dept = new Dept(50,"Help","shanghai");
        int update = deptServiceImpl.updateDept(dept);
        if(update>=0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }
    /*注解
    * */
    @Test
    public void selectByNameOrAge(){
       List<Dept> lists = deptServiceImpl.selectByNameOrAge(10,"OPERATIONS");

       for (Dept list: lists){
           System.out.println(list);
       }
    }
    /*
    * 多条件查询
    * */
    @Test
    public void selectCondition(){
        Dept dept = new Dept();
        dept.setDeptno(60);
        dept.setDname("department");
        dept.setLoc("shanghai");
        List<Dept> lists = deptServiceImpl.selectCondition(dept);
        for (Dept list :lists) {
            System.out.println(list);
        }
    }
   /* @Test
    public void selectByIds(){
        ArrayList<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        List<Dept> lists = deptServiceImpl.selectByIds(list);
        for (Dept listId : lists){
            System.out.println(listId);
        }
    }*/
}
